package jtech.core;

import static javax.sound.sampled.AudioFormat.Encoding.PCM_SIGNED;

import java.awt.Dimension;
import java.awt.DisplayMode;
import java.awt.Point;

import javax.sound.sampled.AudioFormat;
import javax.swing.JFrame;

import jtech.Drawer;

public class Sys {

	private static AudioFormat playbackFormat = new AudioFormat(PCM_SIGNED, 44100, 16, 2, 4, 44100, false);
	
	private static SoundSystem soundSystem = SoundSystem.getInstance();
	private static AwtSystem awtSystem = AwtSystem.getInstance();
	private static Loader loader = Loader.getInstance();
	private static Drawer drawer = Drawer.getInstance();
		
	public static void init() {
		soundSystem.init(playbackFormat, 32);
		awtSystem.init();
	}
	
	public static void shutdown() {
		soundSystem.destroy();
		awtSystem.destroy();
	}
	
	public static void sleep(float secs) {
		awtSystem.sleep(secs);
	}
	
	public static void exit() {
		awtSystem.exit();
    }
	
    public static float time() {
    	return awtSystem.time();
    }
    
    public static JFrame getWindow() {
    	return awtSystem.getWindow();
    }
    
    public static void loadImage(String name, String path) {
    	loader.loadImage(name, path);
    }
    
    public static void loadSound(String name, String path) {
    	loader.loadSound(name, path, playbackFormat);
    }
    
    public static void playSound(String name, boolean blocking) {
		soundSystem.play(name, blocking);
	}
    
    public static boolean isKeyPressed(int key) {
    	return awtSystem.isKeyPressed(key);
    }
    
    public static boolean isKeyDown(int key) {
    	return awtSystem.isKeyDown(key);
    }
    
    public static boolean isKeyReleased(int key) {
    	return awtSystem.isKeyReleased(key);
    }
    
    public static boolean isButtonDown(int button) {
    	return awtSystem.isButtonDown(button);
    }
    
    public static boolean isButtonPressed(int button) {
    	return awtSystem.isButtonPressed(button);
    }
    
    public static boolean isButtonReleased(int button) {
    	return awtSystem.isButtonReleased(button);
    }

    public static boolean isRelativeMouseMode() {
		return awtSystem.isRelativeMouseMode();
	}

	public static void setRelativeMouseMode(boolean relativeMouseMode) {
		awtSystem.setRelativeMouseMode(relativeMouseMode);
	}

	public static void setMouseVisible(boolean visible) {
		awtSystem.setMouseVisible(visible);
	}

	public static boolean isMouseVisible() {
		return awtSystem.isMouseVisible();
	}

	public static void updateMousePosition() {
		awtSystem.updateMousePosition();
	}

	public static void updateInputState() {
		awtSystem.updateInputState();
	}

	public static int getMouseX() {
		return awtSystem.getMouseX();
	}

	public static int getMouseY() {
		return awtSystem.getMouseY();
	}

	public static int getMouseWheel() {
		return awtSystem.getMouseWheel();
	}

	public static Point getWindowCenter() {
		return awtSystem.getWindowCenter();
	}

	public static Dimension getWindowSize() {
		return awtSystem.getWindowSize();
	}

	public static DisplayMode getDisplayMode() {
		return awtSystem.getDisplayMode();
	}

	public static boolean isFullScreen() {
		return awtSystem.isFullScreen();
	}

	public static void setFullScreenMode(DisplayMode displayMode) {
		awtSystem.setFullScreenMode(displayMode);
	}

	public static void setWindowMode(Dimension windowSize) {
		awtSystem.setWindowMode(windowSize);
	}

	public static void setWindowMode(int w, int h) {
		awtSystem.setWindowMode(w, h);
	}
	
	public static Drawer getDrawer() {
		return drawer;
	}

	public static void main(String[] args) {
    	init();
    	try {
    		loadSound("hit", "C:/java-dev/workspace/jtech/hitsound.wav");
    		for (int i = 0; i < 25; i++) {
	    		playSound("hit", false);
	    		sleep(.07f);
    		}
    		setFullScreenMode(new DisplayMode(1920, 1080, 32, 60));
    		sleep(.2f);
    		playSound("hit", true);
    		sleep(.2f);
    		playSound("hit", true);
    		sleep(.2f);
    		playSound("hit", true);
    		sleep(.2f);
    		playSound("hit", true);
    		sleep(.2f);
    		playSound("hit", true);
    		sleep(3f);
    	} finally {
    		shutdown();
    	}
	}
    
}
